package com.appbee.cm.client.nav.presenter;

import java.util.HashMap;

import javax.inject.Inject;

import com.appbee.cm.client.nav.ui.ISimpleNavStyle;
import com.appbee.cm.client.nav.ui.NavSettingsView;
import com.appbee.core.client.modular.IModulRegistry;
import com.appbee.core.client.modular.SettingsView;
import com.appbee.core.client.modular.impl.ActivityModul;
import com.google.gwt.inject.client.AsyncProvider;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class SimpleNavActivityModul extends ActivityModul
{
	private static final String ID = "nav.simplenav";
	private final IModulRegistry registry;
	private final HashMap<String, StyleWrap> styleMap = new HashMap<String, StyleWrap>();
	private final AsyncProvider<NavSettingsView> settingsView;

	@Inject
	public SimpleNavActivityModul(IModulRegistry registry,
									AsyncProvider<SimpleNavActivity> simpleNavProvider,
									AsyncProvider<NavSettingsView> settingsView)
	{
		this.registry = registry;
		this.settingsView = settingsView;
		setDefaultActivty(simpleNavProvider);
	}

	public void register()
	{
		registry.register(ID, this);
	}

	public void addStyle(String id, String name, ISimpleNavStyle style)
	{
		StyleWrap wrap = new StyleWrap();
		wrap.id = id;
		wrap.name = name;
		wrap.style = style;
		styleMap.put(id, wrap);
	}

	@Override
	public String getName()
	{
		return "Simple nav";
	}

	@Override
	public String getId()
	{
		return ID;
	}

	public class StyleWrap
	{
		ISimpleNavStyle style;
		String id;
		String name;
	}

	@Override
	public void getSettingsView(final AsyncCallback<SettingsView> callback)
	{
		settingsView.get(new AsyncCallback<NavSettingsView>()
		{

			@Override
			public void onSuccess(NavSettingsView result)
			{
				callback.onSuccess(result);
			}

			@Override
			public void onFailure(Throwable caught)
			{
				callback.onFailure(caught);
			}
		});
	}

}
